Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
POST to backend is returning a 404. (React => Express)

I've made a fairly simple register/login form for my backend to save to a database. It was working a couple days ago, and now nothing. When I make the fetch call the payload is filled out appropriately. My terminal tells me 'POST /api/v1/users/register 404 13.504 ms - 161'. My fetch request looks like:

        const handleRegisterSubmit = async (e) => {
         e.preventDefault()
         await fetch('http://localhost:3333/api/v1/users/register', {
          method: 'POST',
          mode: 'cors',
          headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
          },
          body: JSON.stringify({
            dealershipname: registerForm.dealershipname,
            password: registerForm.password,
            streetadress: registerForm.streetadress,
            city: registerForm.city,
            state: registerForm.state,
            zip: registerForm.zip,
            phone: registerForm.phone,
            email: registerForm.email
           })
         })
        .then(res => res.json())
        .then(data => {
            if (data.error) {
                setError(data.error)
            } else {
                navigate('/porsche')
            }
        })
}

My backend route looks like:

    router.post('/register', async (req, res) => {
    // check for username and password on req
   if (!req.body.dealershipname || !req.body.password) {
     return res.status(400).json({
       error: 'Please include username and password'
     })
   }

  // check database for existing user 
  const user = await models.User.findOne({
    where: {
     dealershipname: req.body.dealershipname
    }
  })
 // if exists, send error
 if (user) {
   return res.json(400).json({
     error: 'Username already in use. Pick another'
   })
  }
// hash password
const hash = await bcrypt.hash(req.body.password, 10)
// create user
const newUser = await models.User.create({
   dealershipname: req.body.dealershipname,
   password: hash,
   streetadress: req.body.streetadress,
   city: req.body.city,
   state: req.body.state,
   zip: Number(req.body.zip),
   phone: Number(req.body.phone),
   email: req.body.email
  })

// respond with success message
 return res.status(201).json(newUser)
})

My server is running fine. I've set the backend port to 3333 in case that it just needed some room from the front end port. The errors I'm getting in the browser are the same thing. Any help or suggestions would be a lifesaver.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda